<template>
	<div class="white-box">
		<div class="task-one">
			<div class="task-one__item">
				<span class="task-one__label">文章标题：</span>
				<el-input placeholder="输入文章标题" v-model.trim="search_text" size="default" clearable></el-input>
			</div>
			<div class="task-one__btn clearfix">
				<el-button type="primary" :loading="search_btn" :icon="Search" @click="handleSearch">搜索</el-button>
			</div>
		</div>

		<div class="table-mb">
			<el-button type="primary" :icon="CirclePlus" @click="handleAdd">添加</el-button>
		</div>

		<el-table class="table-mb" v-loading="loading" :data="arr_data" :header-cell-style="{ background: '#F5F7FA' }"
			element-loading-background="rgba(255, 255, 255, 0.6)" @selection-change="handleAllSelected">
			<!-- <el-table-column type="selection" width="55" /> -->
			<el-table-column prop="shId" label="文章ID"> </el-table-column>
			<el-table-column prop="title" label="标题"> </el-table-column>

			<el-table-column prop="created_at" label="发布时间"> </el-table-column>
			<el-table-column label="操作" width="160" fixed="right">
				<template #default="{ row }">
					<el-button class="theme-btn" link type="primary" @click="handleEdit(row.shId)">编辑
					</el-button>
					<el-popconfirm :persistent="false" title="确定删除吗？" confirm-button-text="确定" cancel-button-text="取消"
						@confirm="handleDelete(row)">
						<template #reference>
							<el-button class="theme-btn" link type="primary" style="margin-left: 14px">删除</el-button>
						</template>
					</el-popconfirm>
				</template>
				
			</el-table-column>
		</el-table>



		<go-back />
	</div>
</template>

<script setup>
	import {
		getCurrentInstance,
		ref,
		onMounted,
		watch
	} from "vue"
	import OneLoad from "@mixins/one-load"
	import {
		useRouter
	} from "vue-router"
	import {
		Delete,
		CirclePlus,
		Search
	} from "@element-plus/icons-vue"
	import GoBack from "@components/GoBack.vue"

	const router = useRouter()
	const {
		proxy
	} = getCurrentInstance()

	onMounted(() => {
		getList();
	})

	/**
	 * minxin列表加载
	 */
	const {
		page,
		pageSizeNum,
		pageSize,
		loading,
		arr_data,
		totalNums,
		search_text,
		search_btn,
		pubParams,
		pubRefreshParams,
		getdata
	} = OneLoad()
	const type_id = ref("")

	// 切换每页显示条数
	watch(pageSize, (val) => {
		page.value = 1
		pubParams(getList)
	})
	// 跳转第几页
	watch(page, (val) => {
		pubParams(getList)
	})
	const handleSearch = () => {
		search_btn.value = true
		pubRefreshParams(getList)
	}
	const handleClick = (row) => {
		status.value = tabarr.value[row.index].status
		pubParams(getList)
	}

	function getList() {
		let params = {
			page: page.value,
			limit: pageSize.value
		}
		getdata("admin/service/help/list", params)
	}


	function handleDelete(params) {
		proxy.$axios
			.get("admin/service/help/delete", {
				params: {
					shId: params.shId,
				}
			})
			.then((res) => {
				if (res.data.code == 0) {
					proxy.$message({
						message: "操作成功",
						type: "success"
					})
					pubParams(getList)
				} else {
					proxy.$message({
						message: res.data.msg,
						type: "error"
					})
				}
			})
			.catch((err) => {})
	}

	// 添加
	const handleAdd = () => {
		router.push('/HelpAdd')
	}
	// 编辑
	const handleEdit = (eid) => {
		router.push({
			path: '/HelpEdit',
			query: {
				eid
			}
		})
	}
</script>
<script>
	export default {
		name: "NewsList",
	}
</script>

<style lang="less" scoped>
	.status-text {
		color: @themes;
	}
</style>